package com.xy.utils;

import com.xy.exception.ErrorEnum;
import com.xy.exception.ServiceException;

import java.util.Objects;

public class AssertUtil {
    public AssertUtil() {
    }

    public static void assertTrue(boolean bool, ErrorEnum errorEnum) {
        if (!bool) {
            throw new ServiceException(errorEnum.getErrCode(), errorEnum.getErrMessage());
        }
    }

    public static void assertTrue(boolean bool, int errCode, String falseMessage) {
        if (!bool) {
            throw new ServiceException(errCode, falseMessage);
        }
    }

    public static void assertNotNull(Object entity, ErrorEnum errorEnum) {
        if (Objects.isNull(entity)) {
            throw new ServiceException(errorEnum.getErrCode(), errorEnum.getErrMessage());
        }
    }

    public static void assertNotNull(Object entity, int errCode, String falseMessage) {
        if (Objects.isNull(entity)) {
            throw new ServiceException(errCode, falseMessage);
        }
    }

    public static void assertNull(Object entity, ErrorEnum errorEnum) {
        if (!Objects.isNull(entity)) {
            throw new ServiceException(errorEnum.getErrCode(), errorEnum.getErrMessage());
        }
    }

    public static void assertNull(Object entity, int errCode, String falseMessage) {
        if (!Objects.isNull(entity)) {
            throw new ServiceException(errCode, falseMessage);
        }
    }
}
